package com.tianya.controller;

import com.tianya.common.Results;
import com.tianya.domain.dto.TeacherRequestDTO;
import com.tianya.domain.vo.PageResultVO;
import com.tianya.domain.vo.TeacherVO;
import com.tianya.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author TianYaGuoKe
 * @date 2025/5/24 19:54
 * @description TeacherController
 */
@Api("教师管理")
@RestController
@RequestMapping("/teacher")
public class TeacherController {

    @Resource
    private TeacherService teacherService;

    @ApiOperation("获取教师列表")
    @GetMapping("/list")
    public Results<List<TeacherVO>> list() {
        return Results.success(teacherService.getAllTeachers());
    }

    @ApiOperation("分页查询")
    @GetMapping("/page")
    public Results<PageResultVO<TeacherVO>> page(@RequestParam(defaultValue = "1") Integer page,
                                                 @RequestParam(defaultValue = "10") Integer size,
                                                 TeacherRequestDTO teacherRequestDTO) {
        return Results.success(teacherService.pageList(page, size, teacherRequestDTO));
    }

    @ApiOperation("创建教师")
    @PostMapping
    public Results createTeacher(@RequestBody TeacherRequestDTO teacherCreateDTO) {
        teacherService.createTeacher(teacherCreateDTO);
        return Results.success();
    }

    @ApiOperation("编辑教师")
    @PutMapping("/{id}")
    public Results editTeacher(@PathVariable Long id,  @RequestBody TeacherRequestDTO teacherRequestDTO) {
        teacherService.editTeacher(id, teacherRequestDTO);
        return Results.success();
    }

    @ApiOperation("删除教师")
    @DeleteMapping("/{id}")
    public Results deleteTeacher(@PathVariable Long id) {
        teacherService.removeById(id);
        return Results.success();
    }
    @ApiOperation("通过用户id查看教师详情")
    @GetMapping("/user/{userId}")
    public Results<TeacherVO> getTeacherByUserId(@PathVariable Long userId) {
        return Results.success(teacherService.getTeacherByUserId(userId));
    }
    @ApiOperation("查看详情")
    @GetMapping("/{id}")
    public Results<TeacherVO> getTeacher(@PathVariable Long id) {
        return Results.success(teacherService.getTeacherDetailVO(id));
    }
}
